<?php
 /******************************************************************************
 *   GunCMS is an avid supporter of open source software. This is the appropriate 
 *   option if you are creating an open source application with a license 
 *   compatible with the GNU GPL license v3.
 *   For details http://www.gnu.org/licenses/gpl.html
 *   DO NOT USE FOR COMMERCIAL WITHOUT PERMISSION
 *
 * GunCMS Version 1.0.3
 * Copyright(c) 2009-2010, T & L GdbR
 * info@guncms.de
 * 
 * http://www.guncms.de
 ********************************************************************************/
class BgcmsLogfilesBean {
	
	public function __construct() {
		//
	}
		
	public function __destruct() {
		//
	}
	
	public function get_user_agent($db) {
		$sql = "SELECT * FROM " . TBL_ADMIN_USER_ONLINE . " WHERE ip_address = '{$_SERVER['REMOTE_ADDR']}' AND " .
		"user_agent = '{$_SERVER['HTTP_USER_AGENT']}'";
		$res = $db->get_row($sql);
		return	$res;
	}
	
	public function get_logged_user($db) {
		$sql = "SELECT * FROM " . TBL_ADMIN_USER_ONLINE;
		$res = $db->get_results($sql);
		return	$res;
	}
	
	public function create_user_agent($db) {
		$sql = "INSERT INTO " . TBL_ADMIN_USER_ONLINE . " (session_id,activity,ip_address,refurl,user_agent) " .
				"VALUES ('" .session_id(). "', now(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', " .
				"'{$_SERVER['HTTP_USER_AGENT']}')";
    	$res = $db->query($sql);
    	
    	if($res == true) {
    		return $db->insert_id;
    	} else
    		return -1;
	}
	
 	public static function delete_user_agent($db) {
 		$sql = "DELETE FROM " . TBL_ADMIN_USER_ONLINE . " WHERE ADDTIME(activity,'00:15:00')<now()";
    	$res = $db->query($sql);
    	return $res;
    }
	
	/*$member y/n*/
	public function update_user_agent($db, $member) {
		$sql = "UPDATE " . TBL_ADMIN_USER_ONLINE . " SET activity=now(),member='$member' " .
				"WHERE session_id='" .session_id(). "'";
    	$res = $db->query($sql) >= 0;
    	return $res;
	}
}
?>